﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据表 PLM_CP_WGLXD 对应的数据应用功能类。
	/// </summary>
	public class PLM_GG_WGLXDApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IPLM_GG_WGLXDRepository service = new PLM_GG_WGLXDRepository();

        public List<PLM_GG_WGLXDEntity> GetList(Pagination pagination, string keyword, string memo, string begin, string end)
        {
            var expression = ExtLinq.True<PLM_GG_WGLXDEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.LXD.Contains(keyword));
            }
            if (!string.IsNullOrEmpty(memo))
            {
                expression = expression.And(t => t.SM.Contains(memo));
            }
            string extWhere = string.Empty;
            if (!string.IsNullOrEmpty(begin))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and ";
                }
                extWhere += "cast(FCreateDate as datetime) >= '" + begin + "'";
            }
            if (!string.IsNullOrEmpty(end))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " and ";
                }
                extWhere += "cast(FCreateDate as datetime) <= '" + end + "'";
            }
            return service.FindList(expression, pagination);
        }

        public PLM_GG_WGLXDEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.RID == keyValue);
        }

        public void SubmitForm(PLM_GG_WGLXDEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                service.Update(entity);
            }
            else
            {
                entity.RID = Common.GuId();
                service.Insert(entity);
            }
        }
    }
}